let nums = [2, 2, 1, 1, 1, 2, 2]
var majorityElement = function (nums) {
    if (nums.length === 0) {
        return null
    }
    let obj = {}
    let a = nums.length / 2
    for (let i = 0; i < nums.length; i++) {
        if (obj[nums[i]]) {
            obj[nums[i]] = obj[nums[i]] + 1
        } else {
            obj[nums[i]] = 1
        }
        if (obj[nums[i]] > a) {
            return nums[i]
        }
    }
};
console.log(majorityElement(nums));
